package com.molyfun.parents.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;

import java.util.List;

/**
 * Created by william(liuchao.hit@gmail.com).
 * Date:28/07/2017.
 */

public abstract class BaseAdapter<T> extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    Context mContext;
    protected List<T> mList;

    public BaseAdapter(Context context) {
        this.mContext = context;
    }

    public void refreshData(List<T> list) {
        clearAll();
        this.mList = list;
        notifyDataSetChanged();
    }

    public void clearAll(){
        if(mList != null){
            mList = null;
            notifyDataSetChanged();
        }
    }

    public void clear(){
        this.mList = null;
        notifyDataSetChanged();
    }

    public void removePosition(int position){
        mList.remove(position);
        notifyDataSetChanged();
    }

    public void addAll(List<T> list) {
        this.mList.addAll(list);
        notifyDataSetChanged();
    }

    @Override
    public int getItemCount() {
        if (mList == null || mList.size() == 0) {
            return 0;
        }
        return mList.size();
    }

}
